home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / xlib06p1.zip / DEMO5.CPP < prev    next >
C/C++ Source or Header  |  1993-09-13  |  5KB  |  149 lines

  1. /*************************************************************************
  2.  
  3. DEMO 5
  4.  
  5. Demonstrates Planar Bitmap Clipping Functions
  6.  
  7. Themie Gouthas
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18. #include "xlib.h"
  19. #include "xpbitmap.h"
  20. #include "xpbmclip.h"
  21. #include "xrect.h"
  22. #include "xbmtools.h"
  23. #include "xline.h"
  24. #include "xtext.h"
  25. /* Macro to make pointer parameters model independent */
  26. #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
  27.  
  28. int i,j;
  29.  
  30. char turtle[] = {
  31.     20,30,
  32. /*  |      .       |       .      |       .      |      .       */
  33.     8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.     8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.     8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.     8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.     8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38.     8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  39.     0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  40.     0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  41.     0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  42.     0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  43.     0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  44.     0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  45.     0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  46.     0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  47.     0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  48.     2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  49.     0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  50.     0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  51.     0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  52.     0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  53.     0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  54.     0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  55.     0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  56.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  57.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  58.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  59.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  60.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  61.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  62.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  63.     };
  64.  
  65.  
  66. char far *vbm;
  67.  
  68. void error(char * string){
  69.   x_text_mode();
  70.   printf("%s\n",string);
  71.   exit(0);
  72. }
  73.  
  74. typedef struct {
  75.   unsigned int  size;           /* valid only for the first header */
  76.   unsigned char ImageWidth;
  77.   unsigned char ImageHeight;
  78.   unsigned int  ImagePtr;
  79.   unsigned int  MaskPtr;
  80. } alignment_header;
  81.  
  82.  
  83. void main(){
  84.     int i,j,k,handle,size,comp_size;
  85.     char far *bm;
  86.  
  87.     alignment_header  far * tempbuff;
  88.     x_set_mode(X_MODE_360x240,360);
  89.     ;NonVisual_Offs=16384;
  90.  
  91.     x_text_init();
  92.     x_set_font(FONT_8x15);
  93.     x_bgprintf(0,0,0,14,0," This is a demo of PBM clipping.");
  94.     getch();
  95.  
  96.     bm=farmalloc(20*30+2);
  97.     x_bm_to_pbm(MK_FP(_DS,turtle),bm);
  98.  
  99.     x_set_cliprect(4,5,50,150);
  100.  
  101.     x_line(0,TopClip-1,320,TopClip-1,23,0);
  102.     x_line(0,BottomClip+1,320,BottomClip+1,23,0);
  103.     x_line((LeftClip<<2)-1,0,(LeftClip<<2)-1,200,23,0);
  104.     x_line((RightClip<<2)+4,0,(RightClip<<2)+4,200,23,0);
  105.  
  106.     for (k=0;k<8;k++){
  107.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  108.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  109.     x_put_pbm(i+k+1,j,0,bm);
  110.     }
  111.  
  112.     x_line(0,TopClip-1,320,TopClip-1,23,0);
  113.     x_line(0,BottomClip+1,320,BottomClip+1,23,0);
  114.     x_line((LeftClip<<2)-1,0,(LeftClip<<2)-1,200,23,0);
  115.     x_line((RightClip<<2)+4,0,(RightClip<<2)+4,200,23,0);
  116.  
  117.     x_rect_fill((LeftClip<<2),TopClip,(RightClip<<2)+3,BottomClip,0,0);
  118.  
  119.     x_bgprintf(0,BottomClip+4,0,14,0," Now the clipping...");
  120.     getch();
  121.  
  122.     for (k=0;k<8;k++){
  123.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  124.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  125.     x_put_pbm_clipxy(i+k+1,j,0,bm);
  126.     }
  127.     for (k=0;k<8;k++){
  128.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  129.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  130.     x_put_pbm_clipxy(i+7+1,j+k,0,bm);
  131.     }
  132.     for (k=7;k>=0;k--){
  133.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  134.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  135.     x_put_pbm_clipxy(i+k+1,j+7,0,bm);
  136.     }
  137.     for (k=7;k>=0;k--){
  138.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  139.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  140.     x_put_pbm_clipxy(i+1,j+k,0,bm);
  141.     }
  142.  
  143.     getch();
  144.     x_text_mode();
  145.     printf("%d %d %d %d\n",LeftClip,TopClip,RightClip,BottomClip);
  146.  
  147. }
  148.  
  149.